

import {addAdmin,editAdminApi} from '../api/admin'
import  {reactive} from 'vue'
import { message } from 'ant-design-vue';

export function  addHook(params) {

      // 表单需要的v-model数据
    let formState=reactive({
        userName:"",
        turename:"",
        phone:"",
        password:"123456",
        power:"1"
    })
    // 调用添加管理员接口方法 和 编辑管理员的方法
    let toAddAdmin=async ()=>{
        if(formState.tokenId){//如果有修改id
           let editRes=await  editAdminApi(formState)
           console.log(editRes)
            if(editRes.success){
                message.success('修改成功')
                    return true
            }
          formState.tokenId=""; //当前的编辑的课程清空
        }else{
              let res=await addAdmin(formState)
                console.log(res,"^^^^^^^^^^^^^^^^^^^^^^")
                if(res.success){
                    message.success('添加成功')
                    // console.log()
                    return true
                }
        }
      
        
    }
    // 点击编辑 做回显
    let toEdit=(item)=>{
        console.log(item,"^^^^^^^^^^^^^^")
        formState.userName=item.userName;
        formState.turename=item.turename;
         formState.power=item.power;
        formState.phone=item.phone;
        formState.tokenId=item.tokenId; //当前的编辑的课程ID
    }
    return {
        formState,
        toAddAdmin,
        toEdit
    }

}

